package com.credithc.signature.job.job;

import com.credithc.signature.common.utils.DateUtil;
import com.credithc.signature.job.client.QyWxClient;
import com.credithc.signature.job.ro.WxRo;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @desc: <br/>
 * @author: Jingbo Hu<br/>
 * @time：2021年07⽉01⽇<br/>
 * @version：v1.0.0<br>
 */
@Slf4j
@Component
public class HomeworkJob {

    @Value("${qywx.key}")
    private String key;

    @Value("${team.members}")
    private List<String> members;

    @Autowired
    private QyWxClient client;

    /**
     * 每天作业定时任务
     *
     * @throws Exception
     */
    @XxlJob("homeworkJob")
    public void homeworkJob() throws Exception {
        String nowTime = DateUtil.getDefaultDateTimeStr();
        int value = LocalDateTime.now().getDayOfWeek().getValue();
        if (value == 6 || value == 7) {
            log.info("现在时间是：{} 今天是星期{}", nowTime, value);
            return;
        }
        String msg = "<div><b>【日清日结提醒】</b></div><div>请于今日16:40之前提交日清日结</div><div>现在时间是：" + nowTime + "</div>";
        WxRo wxRo = new WxRo(key, msg, members);
        client.sendWxText(wxRo);
        log.info(">>>>>>>>>>> 定时任务：【日清日结提醒】发送成功！");
    }
}
